// pages/order/order.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderid:'',
    address:{ },
    order:[],
    sum:0,
    numbers:0,
    has_address: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   // orderId = options.orderId;
    let orderId = options.orderId;
    this.setData({
      orderid:orderId
    });
  },
  onShow: function() {
    this.getOrder();
  },
  /**1
   * 生命周期函数--监听页面显示
   */
  getOrder: function () {
    let _self = this;
    app.http.$ajax({
      url: 'v1.shop/postOrders',
      data: {
        orderid: _self.data.orderid,
      }
    }, {
      success(res) {
        if (res.data.address && !app.util.isUndefined(res.data.address.id)) {
          console.log('afafafaf');
          _self.setData({
            has_address: true
          });
        }
        _self.setData({
          order: res.data.order,
          address: res.data.address
        });
      }
    })
  },
  save:function(e){
    var val = e.currentTarget.id.split(",");
    if (!val[1]) {
      app.error('请先选择地址');
    }
    app.http.$ajax(
      {
        url: 'v1.leescore/pay',
        data: {
          oid: val[0],
          address: val[1]
        }
      },
      {
        success(res) {
          app.success(res.msg);
          setTimeout(() => {
            wx.navigateBack({
              delta: 2
            })
          }, 1000) 
        }
      }
    );
  },
  addAddress() {
    let order_id = this.data.orderid
    let type = 1;
    wx.navigateTo({
      url: '/pages/mine/address?type=1&orderId=' + order_id,
    });
  }
})